/**
 * Created with IntelliJ IDEA.
 * User: ajhin
 * Date: 2/23/14
 * Time: 9:45 PM
 * To change this template use File | Settings | File Templates.
 */
package societyGames
{
import com.societyGames.utility.BitPacker;

import flexunit.framework.Assert;

public class BitPackerTest
{
  [Test]
  public function TestEmpty():void
  {
    var bitPacker:BitPacker = new BitPacker();
    var value:Boolean = bitPacker.getValue(0);
    Assert.assertFalse(value);
    value = bitPacker.getValue(1);
    Assert.assertFalse(value);
  }

  [Test]
  public function TestTrue():void
  {
    var bitPacker:BitPacker = new BitPacker();
    bitPacker.setValue(0, true);
    var value:Boolean = bitPacker.getValue(0);
    Assert.assertTrue(value);

    bitPacker.setValue(0, false);
    value = bitPacker.getValue(0);
    Assert.assertFalse(value);
  }

  [Test]
  public function TestFalse():void
  {
    var bitPacker:BitPacker = new BitPacker();
    bitPacker.setValue(0, false);
    var value:Boolean = bitPacker.getValue(0);
    Assert.assertFalse(value);
  }

  [Test]
  public function TestBoundaryFalse():void
  {
    var bitPacker:BitPacker = new BitPacker();
    Assert.assertFalse(bitPacker.getValue(31));
    Assert.assertFalse(bitPacker.getValue(32));
    Assert.assertFalse(bitPacker.getValue(33));

    bitPacker.setValue(31, false);
    Assert.assertFalse(bitPacker.getValue(31));
    Assert.assertFalse(bitPacker.getValue(32));
    Assert.assertFalse(bitPacker.getValue(33));

    bitPacker.setValue(32, false);
    Assert.assertFalse(bitPacker.getValue(31));
    Assert.assertFalse(bitPacker.getValue(32));
    Assert.assertFalse(bitPacker.getValue(33));

    bitPacker.setValue(33, false);
    Assert.assertFalse(bitPacker.getValue(31));
    Assert.assertFalse(bitPacker.getValue(32));
    Assert.assertFalse(bitPacker.getValue(33));

    bitPacker.setValue(31, true);
    Assert.assertTrue(bitPacker.getValue(31));
    Assert.assertFalse(bitPacker.getValue(32));
    Assert.assertFalse(bitPacker.getValue(33));

    bitPacker.setValue(32, true);
    Assert.assertTrue(bitPacker.getValue(31));
    Assert.assertTrue(bitPacker.getValue(32));
    Assert.assertFalse(bitPacker.getValue(33));

    bitPacker.setValue(33, true);
    Assert.assertTrue(bitPacker.getValue(31));
    Assert.assertTrue(bitPacker.getValue(32));
    Assert.assertTrue(bitPacker.getValue(33));
  }

  [Test]
  public function TestBoundaryTrue():void
  {
    var bitPacker:BitPacker = new BitPacker();
    Assert.assertFalse(bitPacker.getValue(31));
    Assert.assertFalse(bitPacker.getValue(32));
    Assert.assertFalse(bitPacker.getValue(33));

    bitPacker.setValue(31, true);
    Assert.assertTrue(bitPacker.getValue(31));
    Assert.assertFalse(bitPacker.getValue(32));
    Assert.assertFalse(bitPacker.getValue(33));

    bitPacker.setValue(32, true);
    Assert.assertTrue(bitPacker.getValue(31));
    Assert.assertTrue(bitPacker.getValue(32));
    Assert.assertFalse(bitPacker.getValue(33));

    bitPacker.setValue(33, true);
    Assert.assertTrue(bitPacker.getValue(31));
    Assert.assertTrue(bitPacker.getValue(32));
    Assert.assertTrue(bitPacker.getValue(33));

    bitPacker.setValue(31, false);
    Assert.assertFalse(bitPacker.getValue(31));
    Assert.assertTrue(bitPacker.getValue(32));
    Assert.assertTrue(bitPacker.getValue(33));

    bitPacker.setValue(32, false);
    Assert.assertFalse(bitPacker.getValue(31));
    Assert.assertFalse(bitPacker.getValue(32));
    Assert.assertTrue(bitPacker.getValue(33));

    bitPacker.setValue(33, false);
    Assert.assertFalse(bitPacker.getValue(31));
    Assert.assertFalse(bitPacker.getValue(32));
    Assert.assertFalse(bitPacker.getValue(33));
  }

  [Test]
  public function TestSkipBoundary():void
  {
    var bitPacker:BitPacker = new BitPacker();
    Assert.assertFalse(bitPacker.getValue(31));
    Assert.assertFalse(bitPacker.getValue(32));
    Assert.assertFalse(bitPacker.getValue(33));

    bitPacker.setValue(32, true);
    Assert.assertFalse(bitPacker.getValue(31));
    Assert.assertTrue(bitPacker.getValue(32));
    Assert.assertFalse(bitPacker.getValue(33));

    bitPacker.setValue(33, true);
    Assert.assertFalse(bitPacker.getValue(31));
    Assert.assertTrue(bitPacker.getValue(32));
    Assert.assertTrue(bitPacker.getValue(33));

    bitPacker.setValue(31, false);
    Assert.assertFalse(bitPacker.getValue(31));
    Assert.assertTrue(bitPacker.getValue(32));
    Assert.assertTrue(bitPacker.getValue(33));

    bitPacker.setValue(32, false);
    Assert.assertFalse(bitPacker.getValue(31));
    Assert.assertFalse(bitPacker.getValue(32));
    Assert.assertTrue(bitPacker.getValue(33));

    bitPacker.setValue(33, false);
    Assert.assertFalse(bitPacker.getValue(31));
    Assert.assertFalse(bitPacker.getValue(32));
    Assert.assertFalse(bitPacker.getValue(33));
  }

  [Test]
  public function TestSkipBig():void
  {
    var bitPacker:BitPacker = new BitPacker();
    Assert.assertFalse(bitPacker.getValue(81));
    Assert.assertFalse(bitPacker.getValue(82));
    Assert.assertFalse(bitPacker.getValue(83));

    bitPacker.setValue(82, true);
    Assert.assertFalse(bitPacker.getValue(81));
    Assert.assertTrue(bitPacker.getValue(82));
    Assert.assertFalse(bitPacker.getValue(83));

    bitPacker.setValue(83, true);
    Assert.assertFalse(bitPacker.getValue(81));
    Assert.assertTrue(bitPacker.getValue(82));
    Assert.assertTrue(bitPacker.getValue(83));

    bitPacker.setValue(81, false);
    Assert.assertFalse(bitPacker.getValue(81));
    Assert.assertTrue(bitPacker.getValue(82));
    Assert.assertTrue(bitPacker.getValue(83));

    bitPacker.setValue(82, false);
    Assert.assertFalse(bitPacker.getValue(81));
    Assert.assertFalse(bitPacker.getValue(82));
    Assert.assertTrue(bitPacker.getValue(83));

    bitPacker.setValue(83, false);
    Assert.assertFalse(bitPacker.getValue(81));
    Assert.assertFalse(bitPacker.getValue(82));
    Assert.assertFalse(bitPacker.getValue(83));
  }

  [Test]
  public function TestCleanUp():void
  {
    var bitPacker:BitPacker = new BitPacker();
    bitPacker.setValue(33, true);
    Assert.assertEquals(2, bitPacker.packedValues.length);
    Assert.assertEquals(0x0, bitPacker.packedValues[0]);
    Assert.assertEquals(0x2, bitPacker.packedValues[1]);

    bitPacker.setValue(33, false);
    Assert.assertEquals(0, bitPacker.packedValues.length);

    bitPacker.setValue(0, true);
    bitPacker.setValue(33, true);

    Assert.assertEquals(2, bitPacker.packedValues.length);
    Assert.assertEquals(0x1, bitPacker.packedValues[0]);
    Assert.assertEquals(0x2, bitPacker.packedValues[1]);

    bitPacker.setValue(33, false);
    Assert.assertEquals(1, bitPacker.packedValues.length);
    Assert.assertEquals(0x1, bitPacker.packedValues[0]);
  }
}
}
